/*
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

/* Author: Jorge Peña */

#ifndef XRANDR_ENGINE_H
#define XRANDR_ENGINE_H
 
// We need the DataEngine header, since we are inheriting it
#include <Plasma/DataEngine>
#include <QVector>

class QProcess;
class QString;

typedef struct {
    int state;
    QString id;
    QString type;
} Screen;

/**
 * This engine provides the current screens' state
 */
class XRandREngine : public Plasma::DataEngine
{
    // required since Plasma::DataEngine inherits QObject
    Q_OBJECT
 
    public:
        // every engine needs a constructor with these arguments
        XRandREngine(QObject* parent, const QVariantList& args);
 
    protected:
        void init();
        // this virtual function is called when a new source is requested
        bool sourceRequestEvent(const QString& name);
 
        // this virtual function is called when an automatic update
        // is triggered for an existing source (ie: when a valid update
        // interval is set when requesting a source)
        bool updateSourceEvent(const QString& source);
    private:
        QVector<Screen> screens;
        QProcess *xrandr;
        int numScreens;
        int maxW, maxH;
    public slots:
        void parseOutput();
};
 
#endif //< XRANDR_ENGINE_H
